package org.jetnuke.blocks;

import java.net.URLEncoder;

import javax.servlet.http.HttpServletRequest;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IBlock;
import org.jetnuke.common.IBlockInfo;
import org.jetnuke.common.IUserInfo;


public class RssBlock implements IBlock {
	
		/* (non-Javadoc)
	 * @see org.jetnuke.common.IBlock#serviceBlock(javax.servlet.http.HttpServletRequest, org.apache.velocity.VelocityContext, org.jetnuke.common.IBlockInfo, org.jetnuke.common.IUserInfo, org.jetnuke.common.IAdminInfo)
	 */
	public void serviceBlock(HttpServletRequest req, VelocityContext vc,
			IBlockInfo blockInfo, IUserInfo userInfo, IAdminInfo adminInfo)
			throws Exception {
		vc.put("_TITLE",blockInfo.getTitle());
		String url=blockInfo.getRssUrl();
		if(url==null){
			return;
		}
		if(!url.startsWith("http://")){
			if(!url.startsWith("https://")){
				url="http://"+url;
			}
		}
		url=URLEncoder.encode(url,"UTF-8");
		vc.put("url",url);	
	}

}
